package practise.mulitThreads.ChefAndWaiter;


import java.util.concurrent.Callable;

/**
 * Created by richard on 4/27/14.
 */
public class Customer implements Callable<Order>{
    private  static final int ORDER_TIME=2000;
    String name;
    Order order;
    private Resturant resturant;
    public Resturant getResturant() {
        return resturant;
    }

    public void setResturant(Resturant resturant) {
        this.resturant = resturant;
    }

    public String getDishName() {
        return dishName;
    }

    public void setDishName(String dishName) {
        this.dishName = dishName;
    }

    String dishName;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }


    private void callWaiterAndSetOrder() throws InterruptedException {
          Thread.sleep(ORDER_TIME);
    }

    @Override
    public Order call() throws Exception {
        Waiter waiter = resturant.callAWaiter(this);
        resturant.getWaiters().remove(waiter);
        callWaiterAndSetOrder();
        Order order1 = new Order();
        order1.setCustomerName(getName());
        order1.setDishName(getDishName());
        return order1;
    }
}
